<?php

/**
 * Description of the relationship between movies and the actors
 * that star in them
 *
 * @author Scott McKay
 */
 
 class Application_Model_MoviehasActor extends Zend_db_Table {
 	
 	protected $_name = 'Movie_has_Actor';
 	
 	/**
 	 * This function returns the name of the Actors in a specified
 	 * Movie
 	 *
 	 * @params The ID of the movie
 	 */
 	public function getActors($id) {
 		$sql = "SELECT * FROM Movie_has_Actor, Actor" .
 				" WHERE" .
 				" Movie_has_Actor.Actor_ID = Actor.Actor_ID AND" .
 				" Movie_has_Actor.Movie_ID = ?";
 				
 		$params = array($id);
 		return $this->getAdapter()->query($sql, $params)->fetchAll();
 	}
 	
 	 public function getMovies($id) {
 		$sql = "SELECT * FROM Movie_has_Actor, Movie" .
 				" WHERE" .
 				" Movie_has_Actor.Movie_ID = Movie.Movie_ID AND" .
 				" Movie_has_Actor.Actor_ID = ?";
 				
 		$params = array($id);
 		return $this->getAdapter()->query($sql, $params)->fetchAll();
 	}
 	
 	/**
 	 * Function to add the relation between a movie and an actor
 	 * 
 	 * @param movie_ID The ID of the movie in the relation
 	 * @param actor_ID The ID of the actor in the relation
 	 */
	public function addMhasA($movie_ID, $actor_ID) {
		$sql = "INSERT INTO Movie_has_Actor (MovieHasActor_ID, Movie_ID, Actor_ID) VALUES (Null, :mid, :aid)";
		$params = array(":mid" => $movie_ID, ":aid" => $actor_ID);
		$this->getAdapter()->query($sql, $params);
	}
	
	public function deleteMovieHasActor($id) {
		$sql = "DELETE FROM Movie_has_Actor WHERE MovieHasActor_ID = ?";
		$params = array($id);
		$this->getAdapter()->query($sql,$params);
	}
	
	//public function updateMhasA($movie_ID, $actor_ID
 }
 
 ?>
